package com.a.b.c.d.e.utils;

import java.awt.*;
import java.awt.event.InputEvent;
import java.util.Random;

/**
 * Created on 2021/9/17.
 *
 * @author yanshuchun
 */
public class MouseMove {
    private static Robot robot;//自动化对象

    static {
        try {
            robot = new Robot();
        } catch (AWTException e) {
            System.out.println(e.getMessage());
        }
    }

    public static void Move(int width, int heigh) {    //鼠标移动函数
        Point mousepoint = MouseInfo.getPointerInfo().getLocation();
        width += mousepoint.x;
        heigh += mousepoint.y;
        try {
            robot.delay(3000);
            robot.mouseMove(width, heigh);
            robot.mousePress(InputEvent.BUTTON1_MASK);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void main(String args[]) {
        Random random = new Random();
        while (true) {
            int i = random.nextInt(500);
            System.out.println("=======第1次移动=======");
            MouseMove.Move(i, i);
            System.out.println("=======第2次移动=======");
            MouseMove.Move(-i, i);
            System.out.println("=======第3次移动=======");
            MouseMove.Move(-i, -i);
            System.out.println("=======第4次移动=======");
            MouseMove.Move(i, -i);
        }
    }

}
